package com.zmj.framework.exception;

import com.zmj.mobile.enums.ExceptionEnum;

/**
 * 自定义code的异常
 */
public class CustomException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private int status;
    private String message;

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public CustomException(int status, String message) {
        super(message);
        this.status = status;
        this.message = message;
    }

    public CustomException(ExceptionEnum exceptionEnum) {
        this(exceptionEnum.getCode(), exceptionEnum.getMsg());
    }

    public CustomException(int status, String template, Object... params) {
        super(String.format(template, params));
        this.status = status;
        this.message = String.format(template, params);
    }

    public CustomException(int status) {
        super();
        this.status = status;
    }

    public CustomException(int status, Throwable cause, String template, Object... params) {
        super(String.format(template, params), cause);
        this.status = status;
        this.message = String.format(template, params);
    }
}
